#pragma once

#include "mccommonapi.h"

#include <vector>
#include <string>

namespace MCCommon
{

class MCAPI StringTokenizer
{
public:
    /**
     * Default constructor.
     * 
     */
    StringTokenizer();

    /**
     * Constructor.
     * 
     * @param tokenStr  The token string.
     * @param delim     Delimiter string.
     */
    StringTokenizer
    (
        const std::string& str,
        const std::string& delim = ";"
    );

    /**
     * Destructor.
     * 
     */
    ~StringTokenizer();

    /**
     * Set token character.
     * Note: the token should be characters like ';', '?'.
     * 
     * @param delim  Delimiter string.
     */
    void SetDelimiter
    (
        const std::string& delim
    );  

    /**
     * Is having more sub-string.
     * 
     * @return True if having more sub-string, otherwise false.
     */
    bool HasMore( ) const;

    /**
     * Get next token string.
     * 
     * @return The next token string.
     */
    std::string NextToken( ) const;

    /**
     * After rewind, we can get the substring from the head.
     * 
     */
    void Rewind() const;

    /**
     * Set token string.
     * 
     */
    void 
    StringTokenizer::SetTokenString
    ( 
        const std::string& str,
        const std::string& delim = ";"
    );
    
private:
    // Token
    std::string fDelim;

    // Token string.
    std::string fString;   

    // The position of substring. 
    // It is a supplementary variable.
    mutable int fCurSubStrPos;  
};

void MCAPI ArrayToString
(
    const std::vector< std::string >& arrStr,
    std::string& tokenString,
    const std::string& delim =";"
);

void MCAPI StringToArray
(
    const std::string& tokenString,
    std::vector< std::string >& arrStr, 
    const std::string& delim =";"   
);

} // end of namespace MCCommon
